package com.world.business.dict.controller;

import com.world.business.dict.domain.DictData;
import com.world.business.dict.domain.vo.DictDataVO;
import com.world.common.controller.BaseController;
import com.world.common.domain.ResponseData;
import com.world.business.dict.domain.query.DictDataAddRequest;
import com.world.business.dict.service.IDictDataService;
import com.world.common.domain.SuccessResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 字典数据 前端控制器
 * </p>
 *
 * @author 邓驴
 * @since 2023-07-27
 */
@Api(tags = "字典数据")
@RestController
@RequestMapping("/dict/data")
public class DictDataController extends BaseController<DictData> {

    @Resource
    private IDictDataService dictDataService;

    /**
     * 字典数据新增
     *
     * @param request 请求参数
     * @return {@link ResponseData} 返回值
     * @author WangYX
     * @date 2023/07/28 11:09
     */
    @ApiOperation("字典数据新增")
    @PostMapping("/add")
    public ResponseData<Long> add(@Validated @RequestBody DictDataAddRequest request) {
        return new SuccessResponseData<>(dictDataService.add(request));
    }

    /**
     * 详情
     *
     * @param id 字典数据Id
     * @return {@link ResponseData}
     * @author WangYX
     * @date 2023/07/28 14:02
     */
    @ApiOperation("详情")
    @GetMapping("/{id}")
    public ResponseData<DictDataVO> get(@PathVariable("id") Long id) {
        return new SuccessResponseData<>(dictDataService.get(id));
    }

    /**
     * 删除
     *
     * @param id 字典数据Id
     * @return {@link ResponseData}
     * @author WangYX
     * @date 2023/07/28 14:05
     */
    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public ResponseData<Void> delete(@PathVariable("id") Long id) {
        dictDataService.delete(id);
        return new SuccessResponseData<>();
    }

}
